package com.teradata.feedProc.beans;

/**
 * Container for field information.
 */
public class FieldInfo {

	private int iFieldIndex;

	private String strFieldName;

	private int iFieldLength;

	private boolean bIsDateType;

	private String strFormat;

	private String strJavaFormat;

	private String strDefaultVal;

	public int getiFieldIndex() {
		return iFieldIndex;
	}

	public void setiFieldIndex(int iFieldIndex) {
		this.iFieldIndex = iFieldIndex;
	}

	public String getStrFieldName() {
		return strFieldName;
	}

	public void setStrFieldName(String strFieldName) {
		this.strFieldName = strFieldName;
	}

	public int getiFieldLength() {
		return iFieldLength;
	}

	public void setiFieldLength(int iFieldLength) {
		this.iFieldLength = iFieldLength;
	}

	public boolean isbIsDateType() {
		return bIsDateType;
	}

	public void setbIsDateType(boolean bIsDateType) {
		this.bIsDateType = bIsDateType;
	}

	public String getStrFormat(boolean origValue) {
		return getJavaFormat(origValue);
	}

	public String getSourceFormat() {
		return strFormat;
	}

	/**
	 * Returns the format of the current date value read in from the source
	 * file.
	 * 
	 * @return A string format that follows a java DateFormat.
	 */
	private String getJavaFormat(boolean origValue) {
		
		if(origValue) {
			return strFormat;
		}
		else {
			new DateFormats();
			if (strJavaFormat == null) {
				strFormat = strFormat.toUpperCase();
				String fixedFormat = DateFormats.findJavaFormat(strFormat);
				this.strJavaFormat = fixedFormat;
			}
			return strJavaFormat;
		}
	}

	public void setStrFormat(String strFormat) {
		this.strFormat = strFormat;
	}

	/**
	 * If the format given does not follow a default DateFormat, this will be
	 * called, and return a format that will be able to create a Date object
	 * without error.
	 * 
	 * @param strValue
	 *            The date value that was read in from the source file.
	 * @return A string format that follows a java DateFormat.
	 */
	public String transformValueForFormat(String strValue) {
		new DateFormats();
		return (strValue != null && (!strValue.trim().equals(""))) ? DateFormats.getFormattedString(strValue, strFormat.toUpperCase()) : strValue;
	}

	public boolean checkFormats(String strFormat) {
		new DateFormats();
		if (DateFormats.findJavaFormat(strFormat) == null) {
			return false;
		} else {
			return true;
		}
	}

	public String getStrDefaultVal() {
		return strDefaultVal;
	}

	public void setStrDefaultVal(String strDefaultVal) {
		if (strDefaultVal == null) {
			strDefaultVal = "";
		}
		this.strDefaultVal = strDefaultVal;
	}
}
